package com.gorkemozbek.rubic.util.struct

final class Feature private (val name: String) {

  require(Feature.isFeatureNameValid(name), "a Feature name can only be alpha-numeric" )

  override def toString: String = ":" + name

}

import com.gorkemozbek.rubic.util.InternCache

object Feature extends InternCache[String, Feature] {

  implicit def stringToFeature(feat: String): Feature = apply(feat)

  def isFeatureNameValid(featureName: String): Boolean = featureName forall { 
    ch => (ch >= 'A' && ch <= 'Z') || 
          (ch >= 'a' && ch <= 'z') || 
          (ch >= '0' && ch <= '9')
  }
  
  protected def valueFromKey(name: String): Feature = new Feature(name)

  protected def keyFromValue(feat: Feature): Option[String] = Some(feat.name)
 
}
